<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  </head>
  <body>
    <input id="upfile" type="file" />
    <img src="" alt="" id="myimg" />
  </body>
  <script>
    $(function () {
      $('#upfile').change(function () {
        var file = this.files[0]
        $('#myimg').attr('src', window.URL.createObjectURL(file))
        var formData = new FormData()
        formData.append('file', file)
        $.ajax({
          url: 'http://2022web/fileupload.php',
          type: 'post',
          contentType: false,
          processData: false,
          data: formData,
          success: function (res) {
            console.log(res)
            // res.data['url'] // 'http://2022web/upload/9.9.jpg'
          },
        })
      })
    })
  </script>
</html>
